package com.mengniu.commerce.admin.controller.system;

import com.mengniu.commerce.admin.api.domain.bo.RemoteSocialBo;
import com.mengniu.commerce.admin.domain.bo.SysSocialBo;
import com.mengniu.commerce.admin.domain.vo.SysSocialVo;
import com.mengniu.commerce.admin.service.system.ISysSocialService;
import com.mengniu.commerce.common.core.domain.R;
import com.mengniu.commerce.common.core.utils.bean.BeanUtils;
import com.mengniu.commerce.common.core.web.controller.BaseController;
import com.mengniu.commerce.common.security.utils.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 社会化关系
 *
 * @author thiszhc
 * @date 2023-06-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/social")
public class SysSocialController extends BaseController {

    @Resource
    private ISysSocialService socialUserService;

    /**
     * 查询社会化关系列表
     */
    @GetMapping("/list")
    public R<List<SysSocialVo>> list() {
        return R.ok(socialUserService.queryListByUserId(SecurityUtils.getUserId()));
    }

    @GetMapping("/{authId}")
    public R<List<SysSocialVo>> info(@PathVariable("authId") String authId) {
        List<SysSocialVo> sysSocialVos = socialUserService.selectByAuthId(authId);
        return R.ok(sysSocialVos);
    }

    @PostMapping("/save")
    public R<Boolean> save(@RequestBody RemoteSocialBo bo) {
        SysSocialBo sysSocialBo = new SysSocialBo();
        BeanUtils.copyProperties(bo, sysSocialBo);
        return R.ok(socialUserService.insertByBo(sysSocialBo));
    }

    @PostMapping("/update")
    public R<Void> update(@RequestBody RemoteSocialBo bo) {
        SysSocialBo sysSocialBo = new SysSocialBo();
        BeanUtils.copyProperties(bo, sysSocialBo);
        socialUserService.updateByBo(sysSocialBo);
        return R.ok();
    }

    @DeleteMapping("/unlock/{socialId}")
    public R<Boolean> unlock(@PathVariable("socialId") String socialId) {
        return R.ok(socialUserService.deleteWithValidById(socialId));
    }

}
